package com.flower.controller;

import com.flower.model.dto.BuyPageQueryDTO;
import com.flower.model.entity.Buy;
import com.flower.result.PageResult;
import com.flower.result.Result;
import com.flower.service.BuyService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName BuyController
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/16 22:55
 *@Version 1.0
 */
@Api("采购管理")
@RestController
@RequestMapping("/buy")
@Slf4j
public class BuyController {
    @Autowired
    private BuyService buyService;

    @GetMapping("/page")
    @ApiOperation("分页查询采购信息")
    public Result<PageResult> pageQuery(BuyPageQueryDTO buyPageQueryDTO) {
        PageResult pageResult = buyService.pageQuery(buyPageQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping
    @ApiOperation("添加/修改采购信息")
    public Result<String> add(@RequestBody Buy buy) {
        log.info("添加/修改");
        buyService.addOrUpdate(buy);
        return Result.success("操作成功");
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除采购信息")
    public Result<String> delete(@PathVariable Integer id) {
        log.info("删除");
        buyService.deleteBuy(id);
        return Result.success("删除成功");
    }
    @PostMapping("/del/batch")
    @ApiOperation("批量删除采购信息")
    public Result<String> deleteBatch(@RequestBody List< Integer> ids){
        log.info("批量删除");
        buyService.deleteBuyBatch(ids);
        return Result.success("批量删除成功");
    }
    //查询已通过审核的采购申请单
    @GetMapping("/passbuy")
    public  Result<PageResult> findPage1(@RequestParam Integer pageNum,
                             @RequestParam Integer pageSize

    ) {
        return Result.success(
                buyService.findPage1(new Page<>(pageNum,pageSize)));
    }
}
